package com.yunxiao.plugin.modular

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.Logger

import java.util.function.BiConsumer;


class Test implements Plugin<Project> {

    @Override
    void apply(Project project) {
        def log = project.logger;

        Properties properties = new Properties()
        Properties moduleProperties = new Properties()
        boolean debug = false;


        try {

            moduleProperties.load(file('module.properties').newDataInputStream())
            debug = Boolean.valueOf(properties.getProperty('DEBUG', "false"))
        } catch (Exception e) {
            e.printStackTrace()
        }

        log.error("开始编译")
        if(debug){
            project.apply plugin: 'com.android.application'
        }else{
            project.apply plugin: 'com.android.library'
        }
        def property = project.findProperty("android");
        def defaultConfig = property["defaultConfig"];
        defaultConfig.properties["minSdkVersion"]=16


        if (defaultConfig != null) {
            defaultConfig.properties.forEach(new BiConsumer() {
                @Override
                void accept(Object o, Object o2) {
                    log.error(o.toString() + ":" + o2.toString())
                }
            })
        } else {
            log.error("找不到")
        }
    }
}